/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.menosehmais.framework.security;

import br.com.caelum.vraptor.ioc.Component;
import br.com.menosehmais.model.ContaDO;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author Rafael Quintino
 */
@Component
public class SecurityDAO {
    
    protected final EntityManager entityManager;
    
    public SecurityDAO(EntityManager entityManager) {
        this.entityManager = entityManager;
    }
    
    public ContaDO findPermitedAccount(String login, String encryptedPassword) {
        Query query = entityManager.createQuery("from UsuarioDO where login = :login and encryptedPassword = :encryptedPassword");
        query.setParameter("login", login);
        query.setParameter("encryptedPassword", encryptedPassword);
        
        ContaDO account = (ContaDO) query.getSingleResult();
        return account;
    }
    
}
